﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DOTNETGROUP.Entities;
using DOTNETGROUP.Data;

public partial class Giang_Vien : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            HienThi_GiangVien(Pager1.CurrentIndex);
            sumPage();
        }
    }

    /// <summary>
    /// Tinh tong so trang va hien thi len phan trang
    /// </summary>
    protected void sumPage()
    {
        int totals = 0;
        TList<GiangVien> tlistGiangViens = DataRepository.GiangVienProvider.GetPaged("", "NgayCapNhat DESC", 0, 0,
            out totals);

        // Hien thi tong so trang
        Pager1.ItemCount = tlistGiangViens.Count;
        if (tlistGiangViens.Count <= Pager1.PageSize)
            Pager1.Visible = false;
        else
            Pager1.Visible = true;
    }

    /// <summary>
    /// Thuc hien hien thi danh sach tin tuc va phan trang
    /// </summary>
    /// <param name="pageNo"></param>
    protected void HienThi_GiangVien(int pageNo)
    {
        int totals = 0;
        TList<GiangVien> tlistGiangViens = DataRepository.GiangVienProvider.GetPaged("", "NgayCapNhat DESC", pageNo - 1, Pager1.PageSize,
            out totals);
        if (tlistGiangViens.Count > 0)
        {
            dtlDsGiangVien.DataSource = tlistGiangViens;
            dtlDsGiangVien.DataBind();
        }
    }

    protected void Pager1_Command(object sender, CommandEventArgs e)
    {
        int currnetPageIndex = Convert.ToInt32(e.CommandArgument);
        Pager1.CurrentIndex = currnetPageIndex;
        sumPage();
        HienThi_GiangVien(currnetPageIndex);
    }

    /// <summary>
    /// Phuong thuc chuyen tieu de co dau thanh khong dau de dua vao link
    /// </summary>
    /// <param name="Char"></param>
    /// <returns></returns>
    public string GetTieuDe(object Char)
    {
        string s = Char.ToString();
        return Common.ConvertToUnSign(s);
    }

    /// <summary>
    /// Format cat chuoi
    /// </summary>
    /// <param name="str"></param>
    /// <param name="n"></param>
    /// <returns></returns>
    public string formatString(string str, int n)
    {
        string kq = "";

        if (str.Length > n)
            kq = str.Substring(0, n + 1) + "...";
        else
            kq = str;

        return kq;
    }
}